﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BAL;
using DAL;

namespace blog.Posts
{
    public partial class PostEdit : blog.Class.PageBase
    {
        Dictionary<string, string> mypost;
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                string postid = Request.QueryString["postid"] == null ? "" : Request.QueryString["postid"].ToString();
                mypost = BAL.DoPost.getpost(Convert.ToInt32(postid));
                if (!IsPostBack)
                {
                    this.postname.Text = mypost["postname"].ToString();
                    this.postcontent.Text = mypost["postcontent"].ToString();
                }
            }
            catch (Exception)
            {
                Response.Status = "403 Forbidden";
                Response.StatusCode = 403;
                Response.End();
            }
        }

        protected void submitpost_Click(object sender, EventArgs e)
        {
            string strpostname = this.postname.Text.ToString();
            string strpostcontent = this.postcontent.Text.ToString();
            DateTime time = DateTime.Now;
            string strnowtime = time.ToString();
            mypost["postname"] = strpostname;
            mypost["postcontent"] = strpostcontent;
            mypost["postdate"] = strnowtime;
            mypost["postuser"] = this.username;
            Model.Post post = new Model.Post(mypost);
            int result = BAL.DoPost.modifypost(post);
            if (result != -1)
            {

                string strtext = @"<Script lauguage='JavaScript'>alert('提交成功! ');</script>";
                Response.Write(strtext);
                //Response.Redirect("~/index.aspx");
            }
            else
                Alert("提交失敗!");
        }
    }
}